package com.yj.config.mybatis.pagination;

import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.property.PropertyTokenizer;
import org.apache.ibatis.reflection.wrapper.ObjectWrapper;

import java.util.List;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/8
 * Author     : Unbelievable9
 **/
public class CustomObjectWrapper implements ObjectWrapper {

    private MetaObject metaObject;
    private Page page;

    public CustomObjectWrapper(MetaObject metaObject, Page page) {
        this.metaObject = metaObject;
        this.page = page;
    }

    @Override
    public Object get(PropertyTokenizer propertyTokenizer) {
        return null;
    }

    @Override
    public void set(PropertyTokenizer propertyTokenizer, Object o) {

    }

    @Override
    public String findProperty(String s, boolean b) {
        return null;
    }

    @Override
    public String[] getGetterNames() {
        return new String[0];
    }

    @Override
    public String[] getSetterNames() {
        return new String[0];
    }

    @Override
    public Class<?> getSetterType(String s) {
        return null;
    }

    @Override
    public Class<?> getGetterType(String s) {
        return null;
    }

    @Override
    public boolean hasSetter(String s) {
        return false;
    }

    @Override
    public boolean hasGetter(String s) {
        return false;
    }

    @Override
    public MetaObject instantiatePropertyValue(String s, PropertyTokenizer propertyTokenizer, ObjectFactory objectFactory) {
        return null;
    }

    @Override
    public boolean isCollection() {
        return false;
    }

    @Override
    public void add(Object o) {

    }

    @Override
    public <E> void addAll(List<E> list) {
        try {
            PageDto pageDto = PageThread.getPageDto();

            if (pageDto != null) {
                page.setPageNumber(pageDto.getPageNumber());
                page.setPageSize(pageDto.getPageSize());
                page.setTotalItem(pageDto.getTotalItem());
                page.setTotalPage(pageDto.getTotalPage());
                page.setPageResult(list);
            }
        } finally {
            PageThread.cleanPageDto();
        }
    }
}
